﻿using System;
using System.ServiceModel;
using FastNet.Internal;

namespace FastNet
{
	[CallbackBehavior( ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false, AutomaticSessionShutdown = true )]
	internal sealed class FastClientCallbackChannel : ICommandChannel, IDisposable
	{
		public void Send( Byte[] data )
		{
			var client = m_client;

			if ( client != null )
			{
				m_client.ReceiveSend( data );
			}
		}


		public void Open( String username, String password )
		{
			throw new NotImplementedException();
		}


		public void Dispose()
		{
			m_client = null;
		}


		internal void Associate( FastClient client )
		{
			Logic.Check<ArgumentNullException>( client != null, "client" );
			Logic.Check<InvalidProgramException>( m_client == null, "This client has already been associated." );

			m_client = client;
		}


		private FastClient m_client	= null;
	}
}
